Ext.define('MyDesktop.App', {
    extend: 'Ext.ux.desktop.App',

    requires: [
        'Ext.window.MessageBox',
        'Ext.ux.desktop.ShortcutModel',
        'MyDesktop.AdminInfo',
        'MyDesktop.NewsCategory',
        'MyDesktop.NewsInfo',
        'MyDesktop.TabWindow',
        'MyDesktop.BogusMenuModule',
        'MyDesktop.BogusModule',
        'MyDesktop.Settings'
    ],

    init: function() {
        // custom logic before getXYZ methods get called...

        this.callParent();

        // now ready...
    },

    getModules : function(){
        return [
            new MyDesktop.AdminInfo(),
            new MyDesktop.NewsCategory(),
            new MyDesktop.NewsInfo(),
            new MyDesktop.TabWindow(),
            new MyDesktop.BogusMenuModule(),
            new MyDesktop.BogusModule()
        ];
    },

    getDesktopConfig: function () {
        var me = this, ret = me.callParent();

        return Ext.apply(ret, {
            //cls: 'ux-desktop-black',

            contextMenuItems: [
                { text: AdviceLang.ChangeSetting, handler: me.onSettings, scope: me }
            ],

            shortcuts: Ext.create('Ext.data.Store', {
                model: 'Ext.ux.desktop.ShortcutModel',
                data: [
                    { name: 'Admin Info', iconCls: 'grid-shortcut', module: 'grid-winAdminInfo' },
                    { name: 'News Category', iconCls: 'grid-shortcut', module: 'grid-winNewsCategory' },
                    { name: 'News Info', iconCls: 'grid-shortcut', module: 'grid-winNewsInfo' }
                ]
            }),

            wallpaper: 'wallpapers/desk.jpg',
            wallpaperStretch: false
        });
    },

    // config for the start menu
    getStartConfig : function() {
        var me = this, ret = me.callParent();

        return Ext.apply(ret, {
            title: AdviceLang.CurrentLoginUser + g_userName,
            iconCls: 'user',
            height: 300,
            toolConfig: {
                width: 100,
                items: [
                    {
                        text: AdviceLang.Setting,
                        iconCls:'settings',
                        handler: me.onSettings,
                        scope: me
                    },
                    '-',
                    {
                        text: AdviceLang.LogOff,
                        iconCls:'logout',
                        handler: me.onLogout,
                        scope: me
                    }
                ]
            }
        });
    },

    getTaskbarConfig: function () {
        var ret = this.callParent();

        return Ext.apply(ret, {
            quickStart: [
                { name: 'Admin Info', iconCls: 'icon-grid', module: 'grid-winAdminInfo' },
                { name: 'News Category', iconCls: 'icon-grid', module: 'grid-winNewsCategory' }
                
            ],
            trayItems: [
                { xtype: 'trayclock', flex: 1 }
            ]
        });
    },

    onLogout: function () {
        //Ext.Msg.confirm('Logout', 'Are you sure you want to logout?', LogOff());
        Ext.Ajax.request({
            url: '../HotelWebService.asmx/LoginOff',
            success: function (response, opts) {
                eval('var result =' + response.responseText + ';');
                {
                    if (result.success) {
                        window.location.href = '../Login.html';
                    }
                    else {
                        Ext.Msg.alert(AdviceLang.AlertInfo, AdviceLang.Failed);
                    }
                }
            },
            failure: function (response, opts) {
                Ext.Msg.alert(AdviceLang.AlertInfo, AdviceLang.LoginFailed);
            }
        });
    },

    onSettings: function () {
        var dlg = new MyDesktop.Settings({
            desktop: this.desktop
        });
        dlg.show();
    }
});
